/**
 * 功能描述
 */

define(function (require, exports, module) {
	var Subnav = require("subnav");
	var subnavEvents = require("../handler/subnavEvents");
	var user = require("store").get("user");
	
    var instance = {
        initComponent: function (params,widget) {
        	var subnav = new Subnav({
        		parentNode:".J-subnav",
        		model: {
        			title: "报名退费",
        			items:[{
        				id :"servicePoint",
					      type : "buttongroup",
					      all : {
					    	  show:false,
					    	  first:true
					      },
					      tip : "服务点",
					      keyField :"pkServicePoint",
					      valueField : "name",
//					      url : "api/servicepoint/operableservicepoints",
					      items:user.privateServicePoints,
					      params : function(){
					    	  return{
					    		  fetchProperties:"pkServicePoint,name"
					    	  }
					      },
					      handler : function(key,element){
					    	  widget.get("grid").refresh();
					      }
        			},{
        				id: "destination",
						type: "buttongroup",
						url: "api/destination/query",
//						all: {
//							show : true,
//							first : true
//						},
						tip:"目的地",
						//lazy:true,
						keyField:"pkDestination",
						valueField:"name",
						params:function(){
							return{
								fetchProperties:"pkDestination,name",
							}
						},
						handler:function(){
							widget.get("grid").refresh();
						}
        			},{
        				id : "startDate",
						type : "daterange",
						tip:"开始时间",
						ranges : {
					        "本年": [moment().startOf("year"), moment().endOf("days")]
						},
						handler : function(time){
							 widget.get("grid").refresh();
						}
        			},{
        				id: "save",
						type: "button",
						text: "保存",
						show: false,
						handler: function(){
							subnavEvents.saveChargeBack(widget);
						}
        			},{
        				id: "cancel",
						type: "button",
						text: "返回",
						show: false,
						handler: function(){
							widget.hide([".J-form", ".J-editgrid"]).show(".J-grid");
							widget.get("subnav").hide(["save", "cancel"]).show(["startDate", "destination","servicePoint"]);
							widget.get("grid").refresh();
						}
        			}]
        		}
        	});
        	widget.set("subnav", subnav);
        }
    };
    module.exports = instance;
});
